<!-- 机构表单弹窗 -->
<form id="org-form" lay-filter="org-form" class="layui-form model-form">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入名称" type="text" class="layui-input" minlength="2" maxlength="30"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea" maxlength="255" lay-verify="required"
                      required></textarea>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary close" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="org-form-submit" lay-submit>保存</button>
    </div>
</form>
<script>
    layui.use(['layer', 'crab', 'form'], function () {
        var layer = layui.layer;
        var crab = layui.crab;
        var form = layui.form;

        // 编辑的参数信息
        var org = crab.getFormData();
        if (org) {
            // 回显参数数据
            form.val('org-form', org);
        }

        // 表单提交事件
        form.on('submit(org-form-submit)', function (data) {
            if (org.edit) {
                data.field.id = org.id;
            } else {
                data.field.pid = org.pid;
                data.field.companyId = org.companyId;
            }
            crab.request('/sys/org', data.field, function () {
                layer.msg(org.edit ? '修改成功' : '添加成功', {icon: 1});
                crab.finishPopupCenter();
                // crab.refresh();
            }, org.edit ? 'PUT' : 'POST');
            return false;
        });
    });
</script>